﻿using AutoMapper;
using Common.Communal;
using ERP.Domain.CustomerSupplier;
using MediatR;
using Sell.Api.Write.Application.Command.CustomerCommand;
using Sell.Services.Customers;

namespace Sell.Api.Write.Application.CommandHandlers.CustomerCommadnHandlers
{
    public class CustomerUpdateCommandHandler : IRequestHandler<CustomerUpdateCommand, ApiResult<int>>
    {
        public IMapper Mapper { get; }
        public ICustomerServices customer { get; }
        public CustomerUpdateCommandHandler(ICustomerServices _customer, IMapper _Mapper)
        {
            Mapper = _Mapper;
            customer = _customer;
        }
        /// <summary>
        /// 客户管理修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<int>> Handle(CustomerUpdateCommand request, CancellationToken cancellationToken)
        {
            var list = Mapper.Map<Customer>(request);
            return await customer.UpdateCustomer(list);
        }
    }
}